Libraries

Module, Library and Package

Term Meaning
Module One small handleable unit of code, usually a single file
Library A collection of modules that serve one type of need
Package A container holding various functions and modules for specific tasks
Packages keep code reusable. You reach inside one with the import statement and the dot operator.

Syntax

import module1[, module2, ... moduleN]

Import the Entire Module

import math
print(math.sqrt(25))

Output

5.0
You have to write module_name.function_name() to reach anything inside.

Import a Specific Function

from math import sqrt
print(sqrt(25))

Output

5.0
No need to prefix with math. when calling sqrt() this way.

Import with an Alias

import datetime as dt
print(dt.datetime.now())

Output

2026-09-21 14:05:37.412908
dt is just a shorthand for datetime, handy for long module names.

Import Everything

from math import *
print(sin(90))

Output

0.8939966636005579
The answer looks odd because sin() expects radians, not degrees.